package com.example.hanfu_backend.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.hanfu_backend.entity.Cart;
import com.example.hanfu_backend.mapper.CartMapper;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/cart")
public class CartController {
    @Autowired
    private CartMapper cartMapper;

    @GetMapping("/getCartInfo")
    @Operation(summary = "获取购物车汉服信息")
    public List<Map<String,Object>> getCart(@RequestParam("customerId")Integer customerId) {
        return cartMapper.getCartInfo(customerId);
    }

    @PutMapping("/changeCartInfo")
    @Operation(summary = "通过购物车Id修改信息")
    public int changeCartInfo(@RequestBody Cart cart) {
        return cartMapper.updateById(cart);
    }

    @DeleteMapping("/deleteCartInfo")
    @Operation(summary = "通过购物车Id删除信息")
    public int deleteCartInfo(@RequestParam("cartId") Integer cartId) {
        return cartMapper.deleteById(cartId);
    }

    @PostMapping("/addCartInfo")
    @Operation(summary = "添加商品到购物车")
    public int addCartInfo(@RequestBody Cart cart) {
        return cartMapper.insert(cart);
    }
}
